﻿using Furion.Schedule;
using Microsoft.Extensions.Logging;
using OnWork.DataCenter.BLL.DataCenter;
using OnWork.DataCenter.BLL.Standard;

namespace OnWork.DataCenter.BLL.TaskScheduler
{
    /// <summary>
    /// 流程处理任务
    /// </summary>
    public class ProcessJob : IJob
    {
        private readonly ILogger<ProcessJob> _logger;

        private readonly DSTaskBLL _dSTaskBLL;

        public ProcessJob(ILogger<ProcessJob> logger, DSTaskBLL dSTaskBLL)
        {
            _logger = logger;
            _dSTaskBLL = dSTaskBLL;
        }

        public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
        {
            string jobID = context.JobId;
            long id = long.Parse(jobID);

            var tree = await _dSTaskBLL.GetStandardsTreeByIdAsync(id);
            if (tree != null && tree.Count > 0)
            {
                //记录执行日志
                //string name = await _dSTaskBLL.GetStandardsNameByIdAsync(id);
                //_logger.LogInformation($"开始执行{jobID}任务名称{name}!");
                StandardConvert.ProcessTreeStandards(tree); //执行配置的文件内容
            }

            //  var list = await _dSTaskBLL.GetStandardsByIdAsync(id);
            //if (list != null && list.Count > 0)
            //{
            //    //测试系统
            //    //StandardConvert.ProcessStandards(list, null);

            //    //StandardConvert.ProcessTreeStandards();
            //}

            //_logger.LogInformation($"{context}");
            //return Task.CompletedTask;
        }
    }
}